//
//  Ad_VC.m
//  LoveLove
//
//  Created by 吴志强 on 2019/6/22.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "Ad_VC.h"
#import "QWebVC.h"

@interface Ad_VC ()

@property (nonatomic,strong) UIButton *skip_btn;
@property (nonatomic,assign) int count;
@property (nonatomic,strong) NSTimer *timer;

@end

@implementation Ad_VC

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.count = 5;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countdown) userInfo:nil repeats:YES];
}

- (void) viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void) countdown
{
    self.count --;
    if (self.count == 0) {

        [self.timer invalidate];
        self.timer = nil;
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else{

        [_skip_btn setTitle:[NSString stringWithFormat:@"%ds后跳过",self.count] forState:UIControlStateNormal];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    NSDictionary *dic = @{@"edu_id":@"38",
                          };

    [LLHttpTool post:LLHOST headParams:nil params:dic success:^(NSDictionary *result) {

        NSDictionary *dict = result[@"data"];

        LLStatusModel *model = LLStatusModel.new;
        model.img = [NSString stringWithFormat:@"%@",dict[@"imgurl"]];
        model.url = [NSString stringWithFormat:@"%@",dict[@"url"]];

        self.model = model;
        [self update_view];

    } failure:^(NSString *msg) {

        [SVProgressHUD showErrorWithStatus:msg];
    }];
}

- (void) update_view {

    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LLScreenWidth, LLScreenHeight)];
    if (self.model.img) {
        [image sd_setImageWithURL:[NSURL URLWithString:self.model.img]];
    }
    image.userInteractionEnabled = YES;
    [image addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(show_web)]];
    [self.view addSubview:image];

    _skip_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _skip_btn.frame = CGRectMake(LLScreenWidth-95, 20, 80, 30);
    _skip_btn.layer.cornerRadius = 15;
    _skip_btn.backgroundColor = [UIColor whiteColor];
    [_skip_btn setTitle:@"5s后跳过" forState:UIControlStateNormal];
    [_skip_btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_skip_btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    _skip_btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:_skip_btn];

//    UIView *backview = [[UIView alloc] initWithFrame:CGRectMake(0, LLScreenHeight-90, LLScreenWidth, 90)];
//    backview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
//    [self.view addSubview:backview];
//
//    UILabel *labe = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, LLScreenWidth-40, 30)];
//    labe.textColor = [UIColor whiteColor];
//    labe.font = [UIFont systemFontOfSize:16];
//    if (self.model.title) {
//        labe.text = self.model.title;
//    }
//    [backview addSubview:labe];
//
//    UILabel *labe2 = [[UILabel alloc] initWithFrame:CGRectMake(20, labe.height, LLScreenWidth-40, 60)];
//    labe2.numberOfLines = 0;
//    labe2.textColor = [UIColor whiteColor];
//    labe2.font = [UIFont systemFontOfSize:14];
//    if (self.model.info) {
//        labe2.text = self.model.info;
//    }
//    [backview addSubview:labe2];
}

- (void) show_web
{
    QWebVC *vc = [QWebVC new];
    vc.urlString = self.model.url;
    vc.showLeftBtn = YES;
    [self presentViewController:vc animated:YES completion:nil];
}

#pragma mark - Table view data source
- (void) click {

    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}

@end
